package com.qyer.lxp.model.product.normal;

import com.qyer.lxp.common.framework.util.QyerUtils;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by jiangping on 16/5/18.
 */
@XmlRootElement(name = "pick-drop-model")
@XmlAccessorType(XmlAccessType.FIELD)
public class PickDropModel implements Serializable,Comparable<PickDropModel> {
    private static final long serialVersionUID = 1668881320529385528L;

    /**
     * 接送的时间
     */
    private String time;

    /**
     * 接 PICKUP/送 DROPOFF
     */
    private String type;

    /**
     * 地点
     */
    private String location;

    /**
     * 具体地址
     */
    private String address;

    /**
     * 地点的code,预订时 传入
     */
    private String code;

    /**
     * 产品 code
     */
    private String productCode;

    /**
     * 更新时间
     * 注:非力行字段
     */
    private Date updateTime;

    /**
     * 创建时间
     * 注:非力行字段
     */
    private Date createTime;

    private int id;

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getProductCode() {
        return productCode;
    }

    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "PickDropModel{" +
                "time='" + time + '\'' +
                ", type='" + type + '\'' +
                ", location='" + location + '\'' +
                ", address='" + address + '\'' +
                ", code='" + code + '\'' +
                ", productCode='" + productCode + '\'' +
                ", updateTime=" + updateTime +
                ", createTime=" + createTime +
                '}';
    }

    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.
     * <p>
     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
     * <tt>y.compareTo(x)</tt> throws an exception.)
     * <p>
     * <p>The implementor must also ensure that the relation is transitive:
     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
     * <tt>x.compareTo(z)&gt;0</tt>.
     * <p>
     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
     * all <tt>z</tt>.
     * <p>
     * <p>It is strongly recommended, but <i>not</i> strictly required that
     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
     * class that implements the <tt>Comparable</tt> interface and violates
     * this condition should clearly indicate this fact.  The recommended
     * language is "Note: this class has a natural ordering that is
     * inconsistent with equals."
     * <p>
     * <p>In the foregoing description, the notation
     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
     * <i>expression</i> is negative, zero or positive.
     *
     * @param pickDropModel the object to be compared.
     * @return a negative integer, zero, or a positive integer as this object
     * is less than, equal to, or greater than the specified object.
     * @throws NullPointerException if the specified object is null
     * @throws ClassCastException   if the specified object's type prevents it
     *                              from being compared to this object.
     */
    @Override
    public int compareTo(PickDropModel pickDropModel) {
        int time = 0;
        if(QyerUtils.isEmpty(this.time) && QyerUtils.isEmpty(pickDropModel.getTime())){
            time = 0;
        }else if(QyerUtils.isNotEmpty(this.time) && QyerUtils.isNotEmpty(pickDropModel.getTime())) {
            time = this.time.compareTo(pickDropModel.getTime());
        }else {
            time = 1;
        }
        if(time != 0){
            return time;
        }
        int location = 0;
        if(QyerUtils.isEmpty(this.location) && QyerUtils.isEmpty(pickDropModel.getLocation())){
            location = 0;
        }else if(QyerUtils.isNotEmpty(this.location) && QyerUtils.isNotEmpty(pickDropModel.getLocation())) {
            location = this.location.compareTo(pickDropModel.getLocation());
        }else {
            location = 1;
        }
        if(location != 0){
            return location;
        }
        int address = 0;
        if(QyerUtils.isEmpty(this.address) && QyerUtils.isEmpty(pickDropModel.getAddress())){
            address = 0;
        }else if(QyerUtils.isNotEmpty(this.address) && QyerUtils.isNotEmpty(pickDropModel.getAddress())){
            address = this.address.compareTo(pickDropModel.getAddress());
        }else {
            address = 1;
        }
        if(address != 0){
            return address;
        }
        return 0;
    }
}
